<template>
  <Temp @clear="clear" @close="close">
    <div class="clipplane">
      <div class="first-row">
        <div>裁剪：</div>
        <div>
          <div
            @click="activeTool(item.title)"
            v-for="item in t"
            :key="item.title"
            :style="{
              color:
                active === item.title
                  ? activeColor
                  : defaultColor
            }"
          >
            <Icon
              :title="item.title"
              :name="item.icon"
              :font-size="iconSize"
            />
            <span>{{ item.title }}</span>
          </div>

          <!--          <el-select class="mode" v-model="clipMode" placeholder="请选择裁剪模式" @change="handleModeChange">-->
          <!--            <el-option value="in" label="内部" />-->
          <!--            <el-option value="out" label="外部" />-->
          <!--          </el-select>-->
        </div>
      </div>
    </div>

    <div class="second-row">
      <el-radio v-model="clipMode" label="in"
        >内部</el-radio
      >
      <el-radio v-model="clipMode" label="out"
        >外部</el-radio
      >
    </div>
  </Temp>
</template>

<script>
import Temp from '../temp'
import Icon from '@/components/icon'
import { getAction } from '@/utils/helper'

const clip = {}
export default {
  components: {
    Temp,
    Icon
  },
  inject: ['viewerId'],
  data() {
    return {
      iconSize: 20,
      activeColor: 'rgba(0, 210, 255, 1)',
      defaultColor: '#D2E6F0',
      active: '',
      t: [
        {
          title: '平面',
          icon: 'mian'
        },
        {
          title: 'Box',
          icon: 'juxing'
        }
      ],
      clipMode: 'in'
    }
  },
  async created() {
    const { layerManager } = await getAction(this.viewerId)
    clip[this.viewerId] = layerManager.clip
  },
  methods: {
    close() {
      this.$emit('close')
    },
    clear() {
      this.active = ''
      clip[this.viewerId] && clip[this.viewerId].clear()
    },
    activeTool(title) {
      if (this.active === title) {
        this.clear()
      } else {
        this.clear()
        this.active = title
        switch (title) {
          case '平面':
            clip[this.viewerId].face()
            break
          case 'Box':
            clip[this.viewerId].box(this.clipMode)
            break
          default:
            break
        }
      }
    },
    handleModeChange(val) {
      clip[this.viewerId].setClipMode(val)

      if (this.active === 'Box') {
        clip[this.viewerId].setClipBox()
      }
    }
  },
  watch: {
    clipMode(val) {
      clip[this.viewerId].setClipMode(val)

      if (this.active === 'Box') {
        clip[this.viewerId].setClipBox()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.clipplane {
  display: flex;
  flex-direction: column;

  .first-row {
    display: grid;
    grid-template-columns: minmax(60px, auto) auto;
    align-items: center;
    row-gap: 10px;

    & > div:nth-child(even) {
      display: flex;
      align-items: center;

      & > div {
        display: flex;
        align-items: center;
        padding: 0 4px;

        & > span {
          margin-left: 4px;
          font-size: 14px;
          word-break: keep-all;
          cursor: pointer;
        }
      }
    }

    &-distance {
      display: flex;
      align-items: center;

      &-slider {
        flex: 1;

        ::v-deep {
          .el-slider {
            width: 100%;

            .el-slider__runway {
              height: 4px;
              margin: 0;
              background-color: rgba(255, 255, 255, 0.3);

              .el-slider__bar {
                height: 4px;
                background-color: #fff;
              }

              .el-slider__button-wrapper {
                height: 10px;
                width: 10px;
                top: -9px;
              }
            }

            .el-slider__button {
              width: 10px;
              height: 10px;
              border: none;
            }
          }
        }
      }

      &-input {
        width: 100px;

        ::v-deep {
          .el-input__inner {
            background-color: transparent;
            color: #fff;
            height: 24px;
            border-color: rgba(255, 255, 255, 0.3);
          }
        }
      }
    }

    ::v-deep {
      .el-input__icon,
      .el-range-separator {
        height: 30px;
        line-height: 30px;
        color: #fff;
        padding: 0;
      }

      .el-input__inner,
      .el-range-input {
        background-color: transparent;
        border: none;
        color: #fff;
        height: 30px !important;
        width: 100px;
        border: 1px solid rgba(255, 255, 255, 0.4);
      }
    }
  }
}
</style>
